#include "menu.h"

#define SINGLEPLAYER "Single player"
#define MULTIPLAYER "Multi player"
#define QUIT "Quit"

#define HSINGLEPLAYER "-Single player-"
#define HMULTIPLAYER "-Multi player-"
#define HQUIT "-Quit-"


menu::menu()
{

	bSplashScreenShown = false;
	bGameStarted = false;

	//posSinglePlayer = ;
	//posMultiPlayer = ;
	//posQuit =;

	u8TextColour = 0;
	bTrigger = false;

}

void menu::splashScreen()
{
	for(int i = 0; i < 90; i++) // 90 updates = 3 seconds ;)
	{
	  screen::drawText("Simply Pong", 240, 140);
	  //screen::drawText("", 240, 160);
	  screen::update();
    }

	bSplashScreenShown = true;
}

bool menu::hasSplashBeenShown()
{
	return bSplashScreenShown;
}

void menu::drawMainMenu(char c)
{
	if(bGameStarted)
		return;

	char *sp, *mp, *q;

	sp = (char*)malloc(strlen(HSINGLEPLAYER) + 1);
	mp = (char*)malloc(strlen(HMULTIPLAYER) + 1);
	q = (char*)malloc(strlen(HQUIT) + 1);
	
	strcpy(sp, SINGLEPLAYER);
	strcpy(mp, MULTIPLAYER);
	strcpy(q, QUIT);
    
    switch(c)
    {
	  case 's':
	    strcpy(sp, HSINGLEPLAYER);
	    break;
	  case 'm':
	    strcpy(mp, HMULTIPLAYER);
	    break;
	  case 'q':
	    strcpy(q, HQUIT);
	    break;
	}

	rgb_t rgbColour;

	if(!bTrigger)
		if(u8TextColour < 250)
			{ u8TextColour += 2; rgbColour.r = 120; rgbColour.g = 120; rgbColour.b = u8TextColour; }
		else
			bTrigger = true;
	else
		if(u8TextColour > 5)
			{ u8TextColour -= 2; rgbColour.r = 120; rgbColour.g = u8TextColour; rgbColour.b = 120; }
		else
			bTrigger = false;

	rgbColour.a = 0;

	screen::setTextColor(rgbColour);

	screen::drawText("--- Simply Pong ---", 240, 0);
	screen::drawText(sp, 240, 80);
	screen::drawText(mp, 240, 120);
	screen::drawText(q, 240, 160);
	
	free(sp); free(mp); free(q);
}

void menu::startSinglePlayerGame()
{
	bGameStarted = true;
}

bool menu::hasGameStarted()
{
	return bGameStarted;
}
